from __future__ import unicode_literals
import requests
from bs4 import BeautifulSoup
import time
import json
import mgadapter

adapter=mgadapter.mgadapter()
ulist=[]
for i in range(1,21):
    time.sleep(2)
    url='http://hentai3dtube.com/pages/All/ctr/'+str(i)+'/'
    r=requests.get(url,timeout=7)
    content=r.content
    soup=BeautifulSoup(content,'lxml')
    for item in soup.find('ul',attrs={'class':'videos'}).find_all('li'):
        atag=item.find('a')['href']
        atag=atag[atag.index('http://'):]
        print(atag)
        ulist.append(atag)

while len(ulist)>0:
    print(str(len(ulist)))
    try:
        time.sleep(2)
        url=ulist.pop()
        r=requests.get(url,timeout=7)
        content=r.content
        soup=BeautifulSoup(content,'lxml')
        mp4url=soup.find('video',attrs={'id':'html5player'}).find('source')['src']
        # print(mp4url)
        adapter.add_str(mp4url)
    except Exception as e:
        print(e)
        continue

adapter.sub_mit()